//
//  CDVPushJumpPage.m
//  Hello World
//
//  Created by jing zhao on 7/2/15.
//
//

#import "CDVPushJumpPage.h"



@interface CDVPushJumpPage ()
@property (strong, nonatomic)CDVInvokedUrlCommand *commandCallBack;
@end

@implementation CDVPushJumpPage
-(void)pluginInitialize
{
    [super pluginInitialize];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(pushInfo:) name:NOTIFICATION_CDVPUSHJUMPPAGE object:nil];
    
}

-(void)pushJumpToPage:(CDVInvokedUrlCommand*)command
{
    self.commandCallBack = command;
    [self keepCallBackUserDeaults];
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

//notification Center Receive
- (void)pushInfo:(NSNotification*)notification
{
    [self keepCallBackUserDeaults];
}

-(void)keepCallBackUserDeaults
{
    NSDictionary *dic =[[NSUserDefaults standardUserDefaults]objectForKey:SAVEPUSHMESSAGE];
    if(self.commandCallBack && dic)
    {
        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
        [pluginResult setKeepCallbackAsBool:YES];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:self.commandCallBack.callbackId];
        [[NSUserDefaults standardUserDefaults]removeObjectForKey:SAVEPUSHMESSAGE];
    }
}

@end
